/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jsoup;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.*;
import org.jsoup.*;
import org.jsoup.nodes.*;
import org.jsoup.select.*;
/**
 *
 * @author Asep Sucipto
 */
public class JsoupExtract {

    /**
     * @param args the command line arguments
     */
   public static ArrayList<String> Extract(String url)  {
     ArrayList extract= new ArrayList<String>(); 
      ArrayList temp2= new ArrayList<String>(); 
      String temp, judul = null;
       try {
      
     // String url = "http://en.wikipedia.org/wiki/Barack_Obama";
     Document doc = Jsoup.connect(url).get();
      Elements paragraphs = doc.select("p");
      for(Element p : paragraphs)
      { temp=p.text().toString();
        System.out.println(temp);
        temp2.add(temp); 
      } 
      
      //array list to string
      StringBuilder content = new StringBuilder();
        for (Object s : temp2)
        {
         content.append(s);
         content.append("\t");
        }

    System.out.println(content.toString());
//    int start=1, end=50;
//    String meta= content.substring(start, end);
        
     Elements Title = doc.select("title");
    for(Element t : Title)
    {
    judul=t.text().toString();
    System.out.println(t.text());
    }
    
   // extract.add(url);
  //  extract.add(judul);
   // extract.add(meta);
    extract.add(content);
    
       } 
               
    catch (IOException ex) {
      Logger.getLogger(JsoupExtract.class.getName())
            .log(Level.SEVERE, null, ex);
    }
    
    return extract;
    
  }
}
